// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Sonic Team Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer

// States
private alias 0 : SONICTEAM_SETUP
private alias 1 : SONICTEAM_FADEIN
private alias 2 : SONICTEAM_SHOWLOGO
private alias 3 : SONICTEAM_FADEOUT


// ========================
// Events
// ========================

event ObjectUpdate
	switch object.state
	case SONICTEAM_SETUP
		object.timer = 320
		object.state++
		if options.region == 1
			// The sheet's already been loaded in ObjectStartup, which is why it's safe to use this function here without load time fears
			LoadSpriteSheet("Title/SonicTeam.gif")
		end if
		
		SetScreenFade(0x00, 0x00, 0x00, 0xFF)
		break
		
	case SONICTEAM_FADEIN
		if object.timer > 0
			object.timer -= 8
		else
			object.state++
		end if
		
		SetScreenFade(0x00, 0x00, 0x00, object.timer)
		break

	case SONICTEAM_SHOWLOGO
		object.timer++
		if object.timer == 120
			object.timer = 0
			object.state++
		end if
		break

	case SONICTEAM_FADEOUT
		if object.timer < 320
			object.timer += 8
		else
			ResetObjectEntity(object.entityPos, TypeName[Logo], 0, 0, 0)
		end if
		
		SetScreenFade(0x00, 0x00, 0x00, object.timer)
		break
		
	end switch
end event


event ObjectDraw
	if options.region == 0
		// Draw the black background
		DrawRect(0, 0, screen.xsize, screen.ysize, 0x00, 0x00, 0x00, 0xFF)
	end if

	// Draw either Sonic Team Presents or the secret credits screen depending on region
	DrawSpriteScreenXY(options.region, screen.xcenter, screen.ycenter)
end event


event ObjectStartup
	// Loads both here so they're both loaded in memory
	// It can then load one later and it's just an internal ID change
	LoadSpriteSheet("Title/SonicTeam.gif")
	LoadSpriteSheet("Title/Title.gif")
	
	// 0 - Sonic Team presents
	SpriteFrame(-86, -24, 186, 40, 2, 323)
	
	// 1 - Secret Dev Credits
	SpriteFrame(-256, -128, 512, 256, 0, 0)
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Title/Title.gif")
	SpriteFrame(-76, -24, 148, 40, 174, 259)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event